package JDBC;

import java.sql.*;

public class jdbcTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
       String URL="jdbc:mysql://localhost:3306/dai";
       String USER="root";
       String PASSWORD="123456";
       //1.加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        //2.获得数据库连接
        Connection con = DriverManager.getConnection(URL,USER,PASSWORD);
        //3.操作数据库，实现增删改查
        System.out.println("JAVA链接成功");
        Statement stmt=con.createStatement();

//        String s1="INSERT INTO t_student values(101,'张三','18',1111)";
//        String s2="INSERT INTO t_student values(202,'李四','19',2222)";
//        String s3="INSERT INTO t_student values(303,'王五','17',3333)";
//
//        stmt.executeUpdate(s1);
//        stmt.executeUpdate(s2);
//        stmt.executeUpdate(s3);

        ResultSet rs=stmt.executeQuery("SELECT name,xh,age,FROM t_student");
        while (rs.next()){
            System.out.println("姓名："+rs.getString("name")+",学号："+rs.getInt("number"));
        }
    }
}
